package com.xqb.listen.navigation

import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.xqb.listen.ui.main.MainPage
import com.xqb.listen.ui.music.CloudMusicPage
import com.xqb.listen.ui.music.LocalMusicPage
import com.xqb.listen.ui.splash.SplashPage
import com.xqb.listen.utils.FastClickHandleUtil

@Composable
fun INavigation(navControl: NavHostController = rememberNavController()) {
    NavHost(
        navController = navControl,
        startDestination = NavParams.Router.SPLASH.name,
        enterTransition = {
            scaleIn(initialScale = 0.95f , animationSpec = tween(400)) + fadeIn(tween(200))
        },
        popEnterTransition = {
            scaleIn(initialScale = 1.05f , animationSpec = tween(400)) + fadeIn(tween(200))
        },
        exitTransition = {
            scaleOut(targetScale = 1.05f , animationSpec = tween(400)) + fadeOut(tween(200))
        },
        popExitTransition = {
            scaleOut(targetScale = 0.95f, animationSpec = tween(400)) + fadeOut(tween(200))
        }
    )
    {
        composable(NavParams.Router.SPLASH.name){
            SplashPage{
                if(FastClickHandleUtil.isFastClick(500)) return@SplashPage
                navControl.navigate(it.router.name){
                    launchSingleTop = true
                    popUpTo(NavParams.Router.SPLASH.name){
                        inclusive = true
                    }
                }
            }
        }
        composable(NavParams.Router.MAIN.name){
            MainPage{
                if(FastClickHandleUtil.isFastClick(500)) return@MainPage
                navControl.navigate(it.router.name){
                    launchSingleTop = true
                }
            }
        }
        composable(NavParams.Router.LOCAL_MUSIC.name) {
            LocalMusicPage{
                if(FastClickHandleUtil.isFastClick(500)) return@LocalMusicPage
                if(it.router == NavParams.Router.EXIT) navControl.navigateUp()
            }
        }
        composable(NavParams.Router.CLOUD_MUSIC.name) {
            CloudMusicPage()
        }
    }
}